import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        isLogin: false,
        userInfo: {},
        accessToken: ''
    },
    getters: {
        isLogin: state => state.isLogin,
        userInfo: state => state.userInfo,
        accessToken: state => state.accessToken
    },
    mutations: {
        //保存登录状态
        setUserLogin: (state, {isLogin, userInfo, accessToken}) => {
            state.isLogin = isLogin
            state.userInfo = userInfo
            state.accessToken = accessToken
        },
    },
    actions: {
        setUserLogin({commit}, userInfo) {
            commit("setUserLogin", {isLogin: true, userInfo: userInfo, accessToken: userInfo.token})
        },
    }
})

export default store
